<h1>Listing reservations</h1>

<table>
  <tr>
    <th>Arrive date</th>
    <th>Exit date</th>
    <th>Num adults</th>
    <th>Num childre</th>
    <th>Room</th>
    <th>Guest cpf</th>
	<th>Price per day</th>
	<th>Number of days</th>	
	<th>Total cost</th>
  </tr>

<% @reservations.each do |reservation| %>
  <tr>
    <td><%=h reservation.arrive_date %></td>
    <td><%=h reservation.exit_date %></td>
    <td><%=h reservation.num_adults %></td>
    <td><%=h reservation.num_childre %></td>
    <td><%=h reservation.room_id %></td>
    <td><%=h reservation.guest_cpf %></td>	
	<td>
	<%= room = Room.find_by_num(reservation.room_id)
	roomtype = Roomtype.find_by_name(room.rtype)	
	h roomtype.price %>	</td>
	<td><%= number_days = reservation.exit_date.day - reservation.arrive_date.day
	if number_days < 0
		number_days = 30 - (number_days * (-1))
	end
	h number_days %>	</td>	
	<td><%= room = Room.find_by_num(reservation.room_id)
	roomtype = Roomtype.find_by_name(room.rtype)	
	number_days = reservation.exit_date.day - reservation.arrive_date.day
	if number_days < 0
		number_days = 30 - (number_days * (-1))
	end
	h number_days *  roomtype.price%></td>
    <td><%= link_to 'Show', reservation %></td>
    <td><%= link_to 'Edit', edit_reservation_path(reservation) %></td>
    <td><%= link_to 'Destroy', reservation, :confirm => 'Are you sure?', :method => :delete %></td>
  </tr>
<% end %>
</table>
<br />

<%= link_to 'New reservation', new_reservation_path %>
<%= link_to 'Back', :controller => "home#index" %>